package org.iipg.common.data.autoconfig;

import lombok.RequiredArgsConstructor;
import org.apache.http.HttpHost;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient;
import org.iipg.common.data.property.ESProperties;
import org.iipg.common.data.property.FastJsonProperties;
import org.springframework.boot.autoconfigure.http.HttpMessageConverters;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;

/**
 * @author zhuhy163@163.com
 * @Description
 * @date 2021/7/16 上午10:29
 */
@Configuration
@EnableConfigurationProperties(ESProperties.class)
@RequiredArgsConstructor
public class ESClientConfiguration {

    private final ESProperties esProperties;

    @Bean
    @Primary
    public RestHighLevelClient RestHighLevelClient() {
        return new RestHighLevelClient(
                RestClient.builder(
                        new HttpHost(esProperties.getHostName(), esProperties.getPort(), esProperties.getProtocal())));
    }
}
